package 题目集.dfs.图;

import 题目集.拓扑排序.ch01_食物链条数;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

/**
 * 最大食物链计数
 * a -> b，代表a在食物链中被b捕食
 * 给定一个有向无环图，返回
 * 这个图中从最初级动物到最顶级捕食者的食物链有几条
 * 测试链接 : https://www.luogu.com.cn/problem/P4017
 * 拓扑排序版本：{@link ch01_食物链条数}
 */
public class ch03_食物链条数 {
    /**
     * 暴力思路：
     *      dfs+记忆化搜索
     */
    static List<Integer>[] graph;
    static int mod = 80112002;
    static long[] dp;
    static int[] inDegree;
    static int[] outDegree;
    static boolean[] ends;

    public static long dfs(int s) {
        if (dp[s] != -1) {
            return dp[s];
        }
        if (ends[s]) {  //终点
            return 1;
        }
        long res = 0;
        for (Integer to : graph[s]) {
            res += dfs(to);
        }
        dp[s] = res % mod;
        return dp[s];
    }

    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        int m = sc.nextInt();
        graph = new List[n + 1];
        dp = new long[n + 1];
        Arrays.fill(dp, -1);
        for (int i = 1; i <= n; i++) {
            graph[i] = new ArrayList<>();
        }
        inDegree = new int[n + 1];
        outDegree = new int[n + 1];
        ends = new boolean[n + 1];

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph[a].add(b);
            inDegree[b]++;
            outDegree[a]++;
        }
        List<Integer> start = new ArrayList<>();
        for (int i = 1; i < inDegree.length; i++) {
            if (inDegree[i] == 0) {
                start.add(i);
            }
            if (outDegree[i] == 0) {
                ends[i] = true;
            }
        }
        long res = 0;
        for (Integer i : start) {
            res += dfs(i);
            res = res % mod;
        }
        System.out.println(res);
    }
    static  class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
